<template>
  <div>
    <p>{{ chineseCurrency }}</p>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue';

const amount = ref(12345.67);

const chineseCurrency = computed(() => {
  const digits = '零壹贰';
  const units = ['元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟'];
  const decimals = ['角', '分'];
  
  let value = amount.value;
  let result = '';
  let integerPart = Math.floor(value);
  let decimalPart = Math.round((value - integerPart) * 100);
  
  let integerPartStr = integerPart.toString();
  let decimalPartStr = decimalPart.toString();
  
  // 处理整数部分
  for (let i = 0; i < integerPartStr.length; i++) {
    result += digits[parseInt(integerPartStr.charAt(i))] + units[integerPartStr.length - i - 1];
  }
  
  // 处理小数部分
  if (decimalPart > 0) {
    for (let i = 0; i < decimalPartStr.length; i++) {
      result += digits[parseInt(decimalPartStr.charAt(i))] + decimals[i];
    }
  }
  
  return result;
});
</script>